package com.hw.rediscache.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.Cache;
import org.springframework.cache.interceptor.CacheErrorHandler;
import org.springframework.stereotype.Component;

/**
 * @program: spring-data-redis-cache
 * @description: 缓存异常处理类，打印异常，不影响程序的执行
 * @author: hewei
 * @date: 2021-09-18 14:13
 **/
@Slf4j
@Component
public class DefaultCacheErrorHandler implements CacheErrorHandler {
    @Override
    public void handleCacheGetError(RuntimeException e, Cache cache, Object key) {
        log.error(">> CacheGetError：key -> [{}]", key, e);
    }
    @Override
    public void handleCachePutError(RuntimeException e, Cache cache, Object key, Object value) {
        log.error(">> CachePutError：key -> [{}]；value -> [{}]", key, value, e);
    }
    @Override
    public void handleCacheEvictError(RuntimeException e, Cache cache, Object key) {
        log.error(">> CacheEvictError：key -> [{}]", key, e);
    }
    @Override
    public void handleCacheClearError(RuntimeException e, Cache cache) {
        log.error(">> CacheClearError：", e);
    }
}

